package main

type EnterRoomHandler struct {}

func (handler *EnterRoomHandler) Handle(c *Client, model *MessageModel) {
	enterRoomMessage, err := model.parseEnterRoomMessage()

	if enterRoomMessage == nil || err != nil {
		logger.Println("获取房间最大人数 或 玩家编号 失败", err)
		return
	}

	// 房间编号, 房间最大人数, 用户ID, 玩家编号
	c.RoomNo = enterRoomMessage.RoomNo
	c.UserId = enterRoomMessage.UserId
	c.PlayerNo = enterRoomMessage.PlayerNo[0]
	c.MaxNumber = enterRoomMessage.MaxNumber[0]
	// 玩家进入房间
	flag, room := c.EnterRoom()
	if flag {
		logger.Printf("[Client - %s] Joined", c.UserId)
		//CManager.addClient(c)
		CManager.Register <- c
	}
	//TODO 房间人满开始游戏
	if room.isFull() {
		go room.startGame()
	}
}

func (handler *EnterRoomHandler) Support(model *MessageModel) bool {
	return model.isEnterRoomCommand()
}